package ext.csc.component.numbergen.number;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

import ext.csc.component.numbergen.bean.PropertiesBean;
import ext.csc.component.numbergen.utilities.RemoteUtility;

import wt.org.OrganizationServicesHelper;
import wt.org.WTGroup;
import wt.org.WTPrincipalReference;
import wt.org.WTUser;
import wt.session.SessionHelper;
import wt.util.WTException;

public class AdministrationHelper {
	public static String ADMINISTRATOR = "Admin";
	
	public static String getUser(){
		String result = "N.A.";
		WTUser wtuser = null;
		
		PropertiesBean pb = new PropertiesBean();
		String adminGroup = pb.getAdminGroup();
		
		try {
			wtuser = (WTUser) SessionHelper.manager.getPrincipal();
			result = wtuser.getName();
			ArrayList<WTGroup> userGroups = (ArrayList) RemoteUtility.getUserGroups(wtuser);
			for (int i = 0; i < userGroups.size(); i++) {
				WTGroup wtgroup = userGroups.get(i);
				String strGroup = wtgroup.getName();
				if(strGroup.equals(adminGroup)){
					result = ADMINISTRATOR;
					return result;
				}
			}
		} catch (WTException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return result;
	}
}	
